package com.coocaa.ops.admin.v1.homepage.biz.impl;

import com.coocaa.ops.admin.base.AbstractBizImpl;
import com.coocaa.ops.admin.v1.homepage.biz.IHomepageInfoBiz;
import com.coocaa.ops.admin.v1.homepage.mapper.IHomepageInfoHistoryMapper;
import com.coocaa.ops.admin.v1.homepage.mapper.IHomepageInfoMapper;
import com.coocaa.ops.admin.v1.policygroup.mapper.IPolicyGroupInfoHistoryMapper;
import com.coocaa.ops.common.core.base.mapper.IBaseHistoryMapper;
import com.coocaa.ops.common.core.base.mybatis.QueryTemplate;
import com.coocaa.ops.common.core.biz.homepage.entity.HomepageInfoEntity;
import com.coocaa.ops.common.core.biz.homepage.entity.HomepageInfoHistoryEntity;
import com.coocaa.ops.common.core.biz.policygroup.entity.PolicyGroupInfoHistoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author bjh
 * @description 首页信息原始表-biz层接口实现
 * @date 2020-06-15 16:31:15
 */
@Service
public class HomepageInfoBizImpl extends AbstractBizImpl<IHomepageInfoMapper, HomepageInfoEntity> implements IHomepageInfoBiz {
    @Autowired
    private IHomepageInfoHistoryMapper thisHistoryMapper;
    @Autowired
    private IPolicyGroupInfoHistoryMapper policyGroupInfoHistoryMapper;

    @Override
    public IBaseHistoryMapper getHistoryMapper() {
        return thisHistoryMapper;
    }

    @Override
    public HomepageInfoEntity createOriginEntityNewInstance() {
        return new HomepageInfoEntity();
    }

    @Override
    public HomepageInfoHistoryEntity createHistoryEntityNewInstance() {
        HomepageInfoHistoryEntity historyEntity = new HomepageInfoHistoryEntity();
        return historyEntity;
    }

    @Override
    public boolean isHomeHasUsed(Integer homepageId) {
        QueryTemplate<PolicyGroupInfoHistoryEntity> queryTemplate = QueryTemplate.getEqQueryTemplate("flag", 1);
        queryTemplate.lambda().eq(PolicyGroupInfoHistoryEntity::getHomepageId, homepageId);
        return policyGroupInfoHistoryMapper.selectCount(queryTemplate) > 0;
    }
}
